<?php

require_once 'jsppp.php';

class JsPreprocessor
{
    private $rootDir;

    public function __construct($rootDir, $cacheDir)
    {
        $this->rootDir = $rootDir;
        $this->cacheDir = $cacheDir;
    }

    public function Process($fileName)
    {
        $fileName = preg_replace('/(\.js|_js)\Z/i', '', $fileName) . '.js';

        $processor = new JsPPPProcessor($this->rootDir);
        echo $processor->CompileFile($fileName);
    }

    public function GetScriptLinks($fileName, $jsWwwRoot)
    {
        $fileName = preg_replace('/(\.js|_js)\Z/i', '', $fileName) . '.js';

        $processor = new JsPPPProcessor($this->rootDir);
        
        $includedFiles = array();
        $processor->CompileFile($fileName, $includedFiles);

        $result = '';
        foreach($includedFiles as $includedFile)
            $result .= sprintf("<script type=\"text/javascript\" src=\"%s\"></script>", $jsWwwRoot . '/' . $includedFile);
        return $result;
    }
}

if ($_GET)
{
    $args = array();
    foreach($_GET as $key => $value)
        $args[] = $key;

    $preprocessor = new JsPreprocessor('js/', '');
    $preprocessor->Process($args[0]);

    //echo $preprocessor->GetScriptLinks($args[0], 'js');
}


?>
